package com.platform.web.controller.report;

import com.platform.common.core.controller.BaseController;
import com.platform.common.core.domain.AjaxResult;
import com.platform.module.domain.TempRecord;
import com.platform.module.domain.ValveRecord;
import com.platform.module.service.IBaseRoomTempService;
import com.platform.module.service.ITempRecordService;
import com.platform.module.service.IValveRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 阀门统计曲线图
 *
 * @author wangqi
 * @date 2020-08-04
 */
@Controller
@RequestMapping("/report/valve")
public class ValveReportController extends BaseController {

    private String prefix = "report/valve";

    @Autowired
    private IValveRecordService valveRecordService;

    @RequiresPermissions("report:valve:view")
    @GetMapping()
    public String valve(ModelMap mmap)
    {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        mmap.put("beginTime", dateFormat.format(new Date()));
        mmap.put("endTime", dateFormat.format(new Date()));
        return prefix + "/valve";
    }

    /**
     * 室温变化曲线图
     */
    @PostMapping("/valveSummary")
    @ResponseBody
    public AjaxResult valveSummary(ValveRecord valveRecord)
    {
        if(valveRecord.getParams().get("beginTime").equals("") && valveRecord.getParams().get("endTime").equals("")){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            valveRecord.getParams().put("beginTime", simpleDateFormat.format(new Date()));
            valveRecord.getParams().put("endTime", simpleDateFormat.format(new Date()));
        }
        List<ValveRecord> valveRecordList  = valveRecordService.selectValveRecordList(valveRecord);
        return AjaxResult.success(valveRecordList);
    }
}
